/*
 * @Description: 下拉选择检索方式
 * @Author: Zzt
 * @Date: 2022-08-24 15:18:23
 * @LastEditTime: 2023-03-09 11:47:10
 */
import { Button, Dropdown, Menu, MenuProps, Space } from 'antd';
import { CaretDownOutlined, FileSearchOutlined, FileImageOutlined } from '@ant-design/icons';
import { useNavigate } from 'react-router-dom';
import { useEffect } from 'react';

const retrieval = [
  {
    label: (
      <Button type="text" size="large">
        <FileSearchOutlined />
        条目检索
      </Button>
    ),
    key: '/retrieval/entry-search',
    type: 1
  },
  {
    label: (
      <Button type="text" size="large">
        <FileSearchOutlined />
        全文检索
      </Button>
    ),
    key: '/retrieval/full-text',
    type: 2
  },
  {
    label: (
      <Button type="text" size="large">
        <FileSearchOutlined />
        高级检索
      </Button>
    ),
    key: '/retrieval/advance',
    type: 3
  },
  {
    label: (
      <Button type="text" size="large">
        <FileImageOutlined />
        图像检索
      </Button>
    ),
    key: '/retrieval/image-search',
    type: 4
  },
  {
    label: (
      <Button type="text" size="large">
        <FileSearchOutlined />
        音视频检索
      </Button>
    ),
    key: '/retrieval/audio-search',
    type: 5
  },
  {
    label: (
      <Button type="text" size="large">
        <FileSearchOutlined />
        关联检索
      </Button>
    ),
    key: '/retrieval/relevance-search',
    type: 6
  }
];

const DropdownSearch = (props: any) => {
  const { type } = props;
  const navigate = useNavigate();

  const items = retrieval.filter((item) => item.type !== type);

  const onClick: MenuProps['onClick'] = (event) => {
    if (event.key.indexOf('/') !== -1) {
      navigate(event.key);
    }
    // setCurrent([event.key]);
  };
  const search = (value: any) => {
    switch (value) {
      case 1:
        return '条目检索';
      case 2:
        return '全文检索';
      case 3:
        return '高级检索';
      case 4:
        return '图片检索';
      case 5:
        return '音视频检索';
      case 6:
        return '关联检索';
      default:
        return '';
    }
  };

  const menu = <Menu onClick={onClick} items={items} />;
  return (
    <>
      <Dropdown overlay={menu} trigger={['click']}>
        <Space>
          {search(type)}
          <CaretDownOutlined />
        </Space>
      </Dropdown>
    </>
  );
};
export default DropdownSearch;
